﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：DataAccessPerInfoTemp
// 文件功能描述：临时人员资料数据访问层
//
// 
// 创建标识：2012-05-17 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DbAdapter.sqldbAdapter;
using System.Data.SqlClient;

namespace DAO.WaiGaoQiao
{
    public class DataAccessPerInfoTemp
    {
        /// <summary>
        /// 获取临时人员资料数量
        /// </summary>
        /// <returns></returns>
        public int GetPerInfoTempcount()
        {
            sqldb db = new sqldb();
            string query = "select count(1) from FILE_PERSONNEL_VIEW_TEMP";
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }

        /// <summary>
        /// 获取临时人员资料信息
        /// </summary>
        /// <returns></returns>
        public DataSet SelPerInfoTempInfo(int pagesize, int startindex, string strquery)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                int startrow = pagesize * (startindex - 1);
                int endrow = pagesize * startindex + 1;
                string query = "select * from (select ROW_NUMBER() OVER(ORDER BY PID ASC) rownumber,* " +
                               "from FILE_PERSONNEL_VIEW_TEMP " + strquery + ") B "
                             + "where B.rownumber > " + startrow.ToString() + " and B.rownumber < " + endrow.ToString();
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }

        ///// <summary>
        ///// 删除临时人员资料
        ///// </summary>
        ///// <param name="ID"></param>
        ///// <returns></returns>
        //public int DeletePerInfoTemp(string ID)
        //{
        //    int rowcount = 0;
        //    sqldb db = new sqldb();
        //    string query = "select count(1) from Con_MenuConfiguration where MenuId='" + ID + "'";
        //    object obj = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
        //    if (Convert.ToInt32(obj) == 0)
        //    {
        //        query = "Delete from FILE_PERSONNEL where PID = '" + ID + "'";
        //        rowcount = db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
        //    }
        //    else
        //    {
        //        rowcount = 0;
        //    }
        //    return rowcount;
        //}

        /// <summary>
        /// 根据编号获取一条临时人员资料信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataSet GetPerInfoTempInfoOne(string id)
        {
            sqldb db = new sqldb();
            string query = "select * from FILE_PERSONNEL_VIEW_TEMP where PID = '" + id + "'";
            return db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
        }

        /// <summary>
        /// 保存临时人员资料(修改界面下)
        /// </summary>
        /// <param name="supp"></param>
        /// <returns></returns>
        public int SavePerInfoTempEdit(object[] supp)
        {
            sqldb db = new sqldb();
            string query = "update FILE_PERSONNEL set MenuName='" + supp[1] + "',MenuType='" + supp[2] + "',MenuPrice=" + supp[3] + ",MenuRemarks='" + supp[4] + "' where MenuId=" + supp[0];
            int rowcount = db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
            return rowcount;
        }
    }
}
